package com.guo.core.framework.pro;

import cn.hutool.core.lang.Console;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class OverDueTest {

    public static final String SRC = "D:\\MyData\\guozl22\\git\\tms-third\\tms-third-service\\src\\main\\resources\\OverDueTest.txt";

    public static final String OVER_DURE = "select\n" +
        "\t*\n" +
        "from\n" +
        "\tlogistics_otp_dispatch.transport t\n" +
        "where\n" +
        "\tt.customer_order_no = ?\n" +
        "\tand t.distribution_last_flag = 'Y'\n" +
        "\tand t.delete_flag = 0;";

    @org.junit.Test
    public void installSql() throws IOException {
        List<String> list = FileUtils.readLines(new File(SRC), "UTF-8");

        Console.log("\"insert into logistics_otp_dispatch.receipt_overdue (create_user_code,create_user_name,task_no,dispatch_no,overdue_type,overdue_reason,overdue_reas_detail,overdue_desc) values \"");
        list.forEach(param -> {
            String[] p = param.split(" ");

            try {
                Entity result = Db.use("prod").queryOne(OVER_DURE, p[0]);
                if (result == null) {
                    Console.log("没有该订单:{}", p[0]);
                    return;
                }

                String taskNo = result.getStr("task_no");
                StringBuilder builder = new StringBuilder();
                builder.append("('Lixiu','李秀',")
                    .append("'").append( taskNo ).append("','").append(p[1]).append("','1','1','1_01',''),");


//                Console.log(JSONUtil.toJsonStr(result));
                Console.log(builder);
            } catch (SQLException e) {
                e.printStackTrace();
            }

        });

    }

}
